package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.MedicineBean;
import com.project.bean.OutBean;
import com.project.dao.OutDao;
import com.project.service.OutService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;


/**
 * 出库
 */

@Service
@Transactional
public class OutServiceImpl extends ServiceImpl<OutDao, OutBean> implements OutService {
    /**
     * 分页显示所有出库信息
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public IPage<OutBean> findAllOut(int pageNo, int pageSize) {
        Page<OutBean> page = new Page<>(pageNo,pageSize);
        return this.baseMapper.findAllOut(page);
    }


    /**
     * 添加物品
     */
    @Override
    public void addOut(OutBean outBean) {
//        this.save(outBean);
        this.baseMapper.insert(outBean);
//        for (MedicineBean i:list){
//            int id = i.getMeId();
//            this.baseMapper.addMeOut(id,list,num);
//        }
    }

//    @Override
//    public void addMeOut(OutBean outBean, List<MeOutBean> array) {
//        this.baseMapper.addOut(outBean);
//        this.baseMapper.addMeOut(outBean.getOutId(),array);
//    }

    /**
     * //添加出库信息
     * @param outId
     * @param array
     * @param num
     */
    @Override
    public void addMeOut(int outId,int[] array,int num){
        this.baseMapper.addMeOut(outId,num,array);
    }

    /**
     * 根据出库明细id修改领用数量
     */
    @Override
    public void updateOutNum(int Id,int num) {
        this.baseMapper.updateOutNum(Id,num);
    }


    /**
     * 根据出库id查询出库信息
     * @param outId
     * @return
     */
    @Override
    public OutBean findId(int outId) {
        return this.baseMapper.findId(outId);
    }


    /**
     * 根据领用小班、起始日期、结束日期查询出库信息
     * @param outClass
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public IPage<OutBean> findName(int pageNo, int pageSize, String outClass,
                                   LocalDate startTime, LocalDate endTime) {
        Page<OutBean> page = new Page<>(pageNo, pageSize);
        return this.baseMapper.findName(page,outClass,startTime,endTime);
    }



    /**
     * 根据出库信息去删除物品信息
     * @param outId
     * @param meId
     */
    @Override
    public void del(int outId, int meId) {
        this.baseMapper.del(outId,meId);

    }

    @Override
    public void addOuts(OutBean outBean, List<MedicineBean> list) {
        this.save(outBean);
        this.baseMapper.addOuts(outBean.getOutId(),list);
    }
}
